package com.xx566.blog.common;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Properties;

public class XX566Utils {

	public static final int MESSAGE = -1;// 留言

	public static final int ARCHIVE = -2;// 归档

	public static final int CATES = -3;// category分类

	static Properties props = new Properties();

	/**
	 * 获取IP地址
	 * 
	 * @param request
	 * @return
	 */
	public static String getIpAddrByRequest(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;
	}

	static {
		try {
			props.load(XX566Utils.class.getClassLoader().getResourceAsStream(
					"config.properties"));
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

	public static String getProperty(String key) {
		return props.getProperty(key);
	}
}
